/*
 *  Copyright 2008-2010 the original author or authors.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package org.openaecfm.spf.model;

import java.util.ArrayList;
import java.util.List;

/**
 * The complex entity instance.
 * @author Qiu Kuining
 **/
public class ComplexEntityInstance extends EntityInstance {

    private List<SimpleRecord> simple_records = new ArrayList<SimpleRecord>();

    /**
     * Get the simple records.
     * @return
     */
    public List<SimpleRecord> getSimpleRecords() {
        return simple_records;
    }

    /**
     * Set the simple records.
     * @param simple_records
     */
    public void setSimpleRecords(List<SimpleRecord> simple_records) {
        this.simple_records = simple_records;
    }

    public ComplexEntityInstance() {
        super();
    }

    /**
     * Get the NodeType of ComplexEntityInstance.
     * @return
     */
    @Override
    public final NodeType getNodeType(){
        return NodeType.COMPLEX_ENTITY_INSTANCE;
    }

    /**
     * Add a simple record.
     * @param sr
     */
    public void addSimpleRecord(SimpleRecord sr){
        simple_records.add(sr);
    }

    /**
     * To string.
     * @return
     */
    @Override
    public String toString() {
        java.lang.StringBuffer b = new java.lang.StringBuffer();
        b.append(getName()).append("=(");
        for (SimpleRecord simple_record : simple_records) {
            b.append(simple_record);
        }
        b.append(");\n");
        return b.toString();
    }

    /**
     * Add a child node.
     * @param n
     */
    @Override
    public void addChild(Node n) {
        simple_records.add((SimpleRecord)n);
    }
}
